/*
 * @Author: liuYang codkly@gmail.com
 * @Date: 2022-12-05 17:23:28
 * @LastEditors: liuYang codkly@gmail.com
 * @LastEditTime: 2022-12-08 10:52:57
 * @FilePath: \coding\nest\blog_alpha\src\article\article.entity.ts
 * @Description:
 * 暂无备注
 */
import {
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  ManyToMany,
  OneToMany,
  PrimaryGeneratedColumn,
  JoinTable,
} from 'typeorm';
import { BaseEntity } from '../../entity/base.entity';
import { TagEntity } from "../tag/tag.entity";
@Entity('article')
export class ArticleEntity extends BaseEntity {
  @Column({
    nullable: true,
    comment: '标题',
  })
  title: string;

  @Column('mediumtext', {
    nullable: true,
    comment: '内容',
  })
  content: string;

  @Column({
    nullable: true,
    comment: '封面',
  })
  cover: string;

  @Column({
    nullable: true,
    comment: '简介',
  })
  desc: string;

  @Column({
    comment: '阅读数',
    default: 0,
  })
  views: number;
  
  // @Column('simple-array', {
  //   nullable: true,
  //   comment: '标签',
  // })
  // 一篇文章多个标签
  @ManyToMany(() => TagEntity, tag => tag.articles)
  @JoinTable({
    name:'article_tag', //表名字
    joinColumns: [{ name: 'article_id' }],
    inverseJoinColumns: [{ name: 'tag_id' }],
  })
  tags: TagEntity[];
}
